<cpanel include="../../config.php">

<?

/***************************************************************************
 *                                 filters.php
 *                            -------------------
 *   Begin                : Thursday, April 16, 2005
 *   Copyright            : (C) 2005 Point and Code
 *   Domain               : http://www.pointandcode.com/
 *   Email                : support@pointandcode.com
 *   Version              : 1.0.1
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

$html_root_path = '../../';
include $root_path.'common.php';
$page_title = $lang['mail_filters'];
include $root_path.'page_header.php';




$big_wadge_of_stuff = '<cpanel Email="listfilterstable()">';

$big_wadge_of_stuff = str_replace('$', '', $big_wadge_of_stuff);


//
// Split up into lines...
//
$array_of_filters_with_junk = array();
$array_of_filters_with_junk = explode('</tr>', $big_wadge_of_stuff);

$array_of_filters = array();
$i=0;

foreach($array_of_filters_with_junk as $row) {

	// This is the main explode here, for we can get several things from it.
	$temp = explode('<font  size = "2">', $row);
	
	// First, the filter. More on this in a minute...
	$temp2 = explode('</font>', $temp[1]);
	$array_of_filters[$i]['filter'] = trim($temp2[0]);

	// Second, the destination.
	$temp2 = explode('</font>', $temp[2]);
	$array_of_filters[$i]['destination'] = trim($temp2[0]);

	// We could get the delete button too, but it's easier just to recreate it later.

	// Now, let's neaten up the filter bit, shall we?
	$temp3 = explode(':', $array_of_filters[$i]['filter']);
	$array_of_filters[$i]['search_location'] = trim($temp3[0]);
	$temp4 = explode('"', $temp3[1]);
	$array_of_filters[$i]['match_rule'] = trim($temp4[0]);
	$array_of_filters[$i]['search_term'] = trim($temp4[1]);
	
	// We can also neaten up the search location a bit, to make it more human-friendly.
	// Note to self: this should have language abstraction on it at some point.
	switch ($array_of_filters[$i]['search_location']) {
		case "header_to":
			$array_of_filters[$i]['search_location_neat'] = "To";
		break;
		case "header_from":
			$array_of_filters[$i]['search_location_neat'] = "From";
		break;
		case "header_subject":
			$array_of_filters[$i]['search_location_neat'] = "Subject";
		break;
		case "message_body":
			$array_of_filters[$i]['search_location_neat'] = "Body";
		break;
		case "h_X-Spam-Status":
			$array_of_filters[$i]['search_location_neat'] = "SpamAssassin Spam Header";
		break;
		case "message_headers":
			$array_of_filters[$i]['search_location_neat'] = "Any Header";
		break;
	};
	
	// Next!
	$i++;
}


$template->set_filenames(array(
	'body' => $root_path.$template_path.'mail/filters.tpl')
);

$i = 0;
foreach ($array_of_filters as $row) {
	if (!empty($row['filter'])) {
		$template->assign_block_vars('filterrow', array(
			'ROWCLASS' => ($i%2) ? $template_cfg['class_row_1'] : $template_cfg['class_row_2'],
			'SEARCH_LOCATION' => $row['search_location_neat'],
			'MATCH_RULE' => $row['match_rule'],
			'SEARCH_TERM' => $row['search_term'],
			'DESTINATION' => $row['destination'],
			
			'U_EDIT' => 'forwarders_edit.php?address='.$row['address_pre'].'&domain='.$row['domain'].'&forward='.$row['redirect_to'],
			'U_DELETE' => 'filters_delete.php?search_location='.$row['search_location_neat'].'&search_location_2='.$row['search_location'].'&match_rule='.$row['match_rule'].'&search_term='.$row['search_term'].'&destination='.$row['destination'],
			)
		);
	$i++;
	}

}

$template->assign_vars(array(
	'S_ADD_ACTION' => "filters_add_done.php",
));

//
// Woohoo! All done!
//
$template->pparse('body');




include $root_path.'page_tail.php';


?>